from rest_framework.viewsets import ModelViewSet
from django.contrib.auth.models import Group, Permission
from meiduo_admin.serializers.usergroup_serializers import GroupSerializer, PermissionSimpleSerializer
from meiduo_admin.utils import MyPagination
from rest_framework.decorators import action
from rest_framework.response import Response


class GroupView(ModelViewSet):
    """ 用户组表 增删改查 """

    queryset = Group.objects.all().order_by("id")
    serializer_class = GroupSerializer
    pagination_class = MyPagination

    @action(methods=["get"], detail=False)
    def simple(self, request):
        permission_model = Permission.objects.all().order_by("id")
        serializer = PermissionSimpleSerializer(instance=permission_model, many=True)
        return Response(serializer.data)

